package com.jinglin.web.controller;


import com.jinglin.annotation.RecordUserMessage;
import com.jinglin.controller.ABaseController;
import com.jinglin.entity.dto.TokenUserInfoDto;
import com.jinglin.entity.enums.MessageTypeEnum;
import com.jinglin.entity.po.VideoComment;
import com.jinglin.entity.vo.ResponseVO;
import com.jinglin.entity.vo.VideoCommentResultVO;
import com.jinglin.service.VideoCommentService;
import com.jinglin.service.VideoInfoService;
import com.jinglin.web.annotation.GlobalInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * 评论 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2025-03-24
 */
@RestController
@RequestMapping("/comment")
public class VideoCommentController extends ABaseController {
    @Autowired
    private VideoCommentService videoCommentService;
    @Autowired
    private VideoInfoService videoInfoService;
    // 如果是顶级评论，则是没有replyCommentId的
    @PostMapping("/postComment")
    @RecordUserMessage(messageType = MessageTypeEnum.COMMENT)
    public ResponseVO postComment(VideoComment videoComment,String replyCommentId){
        TokenUserInfoDto tokenUserInfoDto = getTokenUserInfoDto();
        videoComment.setUserId(tokenUserInfoDto.getUserId());
        return getSuccessResponseVO(videoCommentService.postComment(videoComment,replyCommentId));
    }
    @PostMapping("/loadComment")
    public ResponseVO loadComment(@NotEmpty String videoId,Integer pageNo,Integer orderType){
        TokenUserInfoDto tokenUserInfoDto = getTokenUserInfoDto();
        VideoCommentResultVO videoCommentResultVO = videoCommentService.loadCommentByVideoId(videoId, pageNo, orderType, tokenUserInfoDto.getUserId());
        return getSuccessResponseVO(videoCommentResultVO);
    }
    @RequestMapping("/topComment")
    @GlobalInterceptor(checkLogin = true)
    public ResponseVO topComment(@NotNull String  commentId) {
        TokenUserInfoDto tokenUserInfoDto = getTokenUserInfoDto();
        videoCommentService.topComment(commentId, tokenUserInfoDto.getUserId());
        return getSuccessResponseVO(null);
    }

    @RequestMapping("/cancelTopComment")
    @GlobalInterceptor(checkLogin = true)
    public ResponseVO cancelTopComment(@NotNull String commentId) {
        TokenUserInfoDto tokenUserInfoDto = getTokenUserInfoDto();
        videoCommentService.cancelTopComment(commentId, tokenUserInfoDto.getUserId());
        return getSuccessResponseVO(null);
    }
}

